#!/usr/bin/python
# -*- coding: utf-8 -*-

from threading import Thread
from time import sleep
import random
from ssh import sshCommand,sshUploadFile

class SshTread(Thread):
    """
    ssh 命令执行线程
    """
    def __init__(self,threadname,hostname,cmd = None,local_file= None,
                 remote_file = None,hostfile = None, filelist = None,
                 exec_type = None,
                 username = 'root', password = '%TGB^YHN',port = 22):
        Thread.__init__(self, name=threadname)
        self.name = threadname
        
        self.hostname = hostname
        self.cmd = cmd
        self.local_file = local_file
        self.remote_file = remote_file
        self.username = username
        self.password = password
        self.port = port
        self.hostfile = hostfile
        self.filelist = filelist
        self.exec_type = exec_type
 
    def run(self):
        
        #print "threadname===>",self.name
        
        if self.exec_type == 'cmd':
    
            sshCommand(self.hostname,cmd = self.cmd, username = self.username,
                       password = self.password,port = self.port)
        else:

            sshUploadFile(self.hostname,local_file = self.local_file,remote_file = self.remote_file,
                          filelist = self.filelist,
                          username = self.username,password = self.password,
                          port = self.port)

       
 
#if __name__ == '__main__':
    #f = open('hostfile').readlines()
    #for line in f:
        ##去掉空格
        #hostname,port,username,password = line.strip().split(':')
        #threadname = "Thread_%s" % hostname
        #task = SshTread(threadname,hostname,username=username,password=password,port=port)
        #task.start()